package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"ocane/models"
	"ocane/utils"
	"time"
)

type ContentListController struct {
	beego.Controller
}

type ContentDetailController struct {
	beego.Controller
}

var redis_key = "contentHotListKey"

func (this *ContentListController) Get(){
	paramsKey := this.GetString("paramskey")
	currentPage,_:= this.GetInt("currentPage")
	currentPageCount, _ := this.GetInt("currentPageCount")
	list := models.QueryList(paramsKey, currentPage, currentPageCount)
	count := models.QueryCountByParams(paramsKey)
	this.Data["json"] = models.Result{Data: ContentListVO{ContentQueryList: list,Count: count},Code: 200}
	this.ServeJSON()
}

type ContentListVO struct {
	ContentQueryList []models.ContentList `json:"content_query_list"`
	Count int `json:"count"`
}

func (this *ContentDetailController) Get() {
	contentId, _ := this.GetInt64("contentId")
	//redis异步埋点统计
	if contentId==0{
		panic(" params is null")
	}
	result := models.QueryDetailById(contentId)
	this.Data["json"] = models.Result{Data: result,Code: 200}
	go logRedis(result.ContentListKey.CompanyName)
	this.ServeJSON()
}




func logRedis(contentId string){
	utils.AddZSet(redis_key,contentId)
}

func AddList()  {
	list := models.ContentList{CompanyId: 1001, CompanyName: "LALAREMOVE", Title: "albabbabab", Desc: "this is test desc", CreateDate: time.Now(), UpdateDate: time.Now(), UserName: "testUserName", UserId: 1,Delete: 0,ImageUrl: "https://www.baidu.com"}
	models.AddContentList(list)
}


